package com.nisco.dms.controller;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.nisco.dms.entity.DictionaryDtl;
import com.nisco.dms.service.DictionaryDtlService;
import com.nisco.dms.service.DictionaryService;
import com.nisco.dms.util.dwz.AjaxObject;
import com.nisco.dms.util.dwz.Page;

@Controller
@RequestMapping(value="/dictdtl")
public class DictionaryDtlController
{
	@Resource
	private DictionaryDtlService dictionaryDtlService;
	@Resource
	private DictionaryService dictionaryService;
	
	private static final String LIST="dictionaryDtl/dictionaryDtlList";
	private static final String CREATE="dictionaryDtl/dictionaryDtlCreate";
	private static final String UPDATE="dictionaryDtl/dictionaryDtlUpdate";
	
	@RequestMapping(value="/list")
	public String list(Page page,String dictId,Model model)
	{
		if(dictId!=null&&!"".equals(dictId))
		{
			model.addAttribute("dictdtls", dictionaryDtlService.findByDictId(page, dictId));
			model.addAttribute("dictId", dictId);
			}
		else
			model.addAttribute("dictdtls", dictionaryDtlService.findAll(page));
		model.addAttribute("dicts", dictionaryService.findAll());
		return LIST;
	}
	
	@RequestMapping(value="/preCreate/{dictId}")
	public String preCreate(@PathVariable(value="dictId")String dictId,Model model)
	{
		model.addAttribute("dictId", dictId);
		return CREATE;
	}
	
	@RequestMapping(value="/preUpdate/{id}")
	public String preUpdate(@PathVariable(value="id")String id,Model model)
	{
		model.addAttribute("dictDtl", dictionaryDtlService.get(id));
		return UPDATE;
	}
	
	@RequestMapping(value="/create")
	public@ResponseBody String create(DictionaryDtl dictionaryDtl)
	{
		dictionaryDtlService.save(dictionaryDtl);
		AjaxObject ajaxObject=new AjaxObject();
		ajaxObject.setMessage("词典明细增加成功");
		//ajaxObject.setNavTabId("moduleListNav_2c92b8113e4502b3013e4503d6fd0000");

		ajaxObject.setRel("dictdtl");
		return ajaxObject.toString();
		
	}
	
	@RequestMapping(value="/update")
	public@ResponseBody String update(DictionaryDtl dictionaryDtl)
	{
		dictionaryDtlService.update(dictionaryDtl);
		AjaxObject ajaxObject=new AjaxObject();
		ajaxObject.setMessage("词典明细更新成功");
		ajaxObject.setRel("dictdtl");
		return ajaxObject.toString();
		
	}
	@RequestMapping(value="/delete/{id}")
	public @ResponseBody String delete(@PathVariable(value="id")String id)
	{
		dictionaryDtlService.delete(id);
		AjaxObject ajaxObject=new AjaxObject();
		ajaxObject.setMessage("词典明细删除成功");
		ajaxObject.setCallbackType("");
		ajaxObject.setRel("dictdtl");
		return ajaxObject.toString();
	}
}
